package com.hd.until;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

public class HttplTestUti {

	static CloseableHttpClient httpClient = HttpClients.createDefault();
	static CloseableHttpResponse response = null;

	public static String doPostHttps(String content) {
		String resp="";
		URIBuilder uriBuilder = new URIBuilder().setScheme("https")
				.setHost("qcore.hengdadai.com").setPort(443)
				.setPath("/ecf-core/DexpreHttpXmlServlet");

		RequestConfig requestConfig = RequestConfig.custom()
				.setSocketTimeout(45000).setConnectTimeout(45000)
				.setConnectionRequestTimeout(45000).build();
		HttpPost httpPost = null;
		try {
			httpPost = new HttpPost(uriBuilder.build());

			httpPost.setConfig(requestConfig);
			// json
			StringEntity httpEntity = new StringEntity(content,
					ContentType.APPLICATION_JSON);
			httpPost.setEntity(httpEntity);
			response = httpClient.execute(httpPost);
			if(response !=null && response.getEntity() !=null){
				
				 System.out.println("--------------------------------------");  
				 System.out.println(response.getStatusLine()); 
				 resp=EntityUtils.toString(response.getEntity());
				 System.out.println("Response content: " + resp);  
				 System.out.println("--------------------------------------");  
				 
			}
			
			
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return resp;
	}

	public void processPost(String path, Map<String, String> params,
			String content) {

	}

}
